package server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.atu.poker.thread.SocketThread;
import com.atu.poker.util.MapUtil;


public class MainSocket {
	public static List<Socket> sockets = new ArrayList<>();
	public static MapUtil<String, Object> seatMap = new MapUtil<>();
	private static Logger logger = LogManager.getLogger(MainSocket.class);

	//不同房间存放的牌
	public static Map<String, List<Integer>> roomCards = new HashMap<>();
	//不同座位存放的牌
	public static Map<String, List<Integer>> seatCards = new HashMap<>();
	//存放玩家押的筹码
	public static Map<String, Integer> seatEscrows = new HashMap<>();
	//存放玩家的筹码，（可能用不到）
	public static Map<String, Integer> seatChips = new HashMap<>();
	//存放结算筹码
	public static Map<String, String> settlementChips = new HashMap<>();
	
	//存放两张牌时玩家拿了两对A
	public static Map<String, List<Integer>> roomDealDoubleAs = new HashMap<>();
	//存放两张牌事玩家得到了A+J或A+Q或A+K
	public static Map<String, List<Integer>> roomDealGongChes = new HashMap<>();
	//玩家拿了五张牌，且五张牌的值小于等于21点
	public static Map<String, List<Integer>> roomFiveGongChes = new HashMap<>();
	
	//玩家摸牌的时候牌型的值大于21，爆了，不少于三张牌的情况
	public static Map<String, List<Integer>> roomBooms = new HashMap<>();
	//玩家摸到五张牌时爆了的情况
	public static Map<String, List<Integer>> roomFiveBooms = new HashMap<>();
	//玩家手中的牌小于16点，不上牌头的情况
	public static Map<String, List<Integer>> roomNotPaiTou= new HashMap<>();
	//保存该房间已经开牌的玩家
	public static Map<String, List<Integer>> roomAlreadyOpenCard = new HashMap<>();
	
	//房间锁，同步对象，避免有玩家同时加入房间导致死锁	
	public static Object object = new Object();
	
	public static void main(String[] args){
		ServerSocket serverSocket;
		try {
			serverSocket = new ServerSocket(6000);
			logger.debug("socket服务器启动成功");
			while (true) {
				Socket socket = serverSocket.accept();
				sockets.add(socket);
				SocketThread socketThread = new SocketThread(socket);
				Thread thread = new Thread(socketThread);
				thread.start();
			}
		} catch (IOException e) {
			logger.error("socket服务器启动失败，请查看端口是否被占用");
			e.printStackTrace();
		}
	}
}
